@layout("/common/default.html",{title:'添加',libs:['form']}){
    <!--form表单-->
    <form class="layui-form"  lay-filter="layui-form-area" id="layui-form-area">
        <input type="hidden" name="id" value="${area.id}">
        <input type="hidden" id="op" name="op" value="${area.op}">

        <div class="layui-fluid">
            <div class="layui-card">
                <div class="layui-card-header">基本信息</div>

                <div class="layui-card-body">
                    <div class="layui-form-item layui-row">

                        <div class="layui-inline layui-col-md9" id="superior" style="display: none">
                            <label class="layui-form-label layui-required">上级区域</label>
                            <input type="hidden" id="parentid" value="${area.parent.id!}">
                            <div class="layui-input-block">
                                <input type="text" id="parent" name="parent.id" placeholder="请输入" autocomplete="off" class="layui-input" >
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label layui-required">区域名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" value="${area.name!}" lay-verify="required" placeholder="请输入"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label layui-required">区域类型</label>
                            <div class="layui-input-block">
                                <#select path="type" value="${area.type!}" items="${fnc.getDictList('sys_area_type')}" placeholder="请选择" layVerify="layVerify"/>
                            </div>
                        </div>

                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label">区域编码</label>
                            <div class="layui-input-block">
                                <input type="text" id="code" name="code" value="${area.code!}" lay-verify="" placeholder="请输入"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>


                        <div class="layui-inline layui-col-md9">
                            <label class="layui-form-label layui-required">排序</label>
                            <div class="layui-input-block">
                                <input type="text" id="sort" name="sort" value="${area.sort!}" lay-verify="required" placeholder="请输入排序"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>

                    </div>
                </div>
            </div>

        </div>
        <div class="form-group-bottom" style="z-index: 200" align="center">
            <button class="layui-btn" lay-filter="btnSubmit" lay-submit>&emsp;提交&emsp;</button>
            <button   id="btnclose" class="layui-btn layui-btn-primary"  >&emsp;取消&emsp;</button>
        </div>

    </form>
<!--js逻辑-->
<script>
    layui.use(['form', 'treeSelect','submitform'], function () {

        var $ = layui.$,
            form = layui.form,
            treeSelect = layui.treeSelect,
            submitform=layui.submitform;
            var parentid=$("#parentid").val();
            if(parentid!=''){
                $("#superior").css("display","block");
            }

            //为表单赋值
            treeSelect.render({
                elem: '#parent',
                title: '区域选择',
                url: '/sys/area/treeData',
                type: '3',
                icon: 'layui-icon layui-icon-app',
                value: '${area.parent.id!}',
                label: '${area.parent.name!}'
            });




        form.on("submit(btnSubmit)", function (data) {
            var field=data.field;
            // 请求后台
            submitform.form('/sys/area/save',field);
            return false;
        });

    });
</script>

@}
